<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">活动类型</label>
        <div class="layui-input-inline">
            <input type="radio" name="activity_big_small" value="2" title="大活动">
            <input type="radio" name="activity_big_small" value="1" title="小活动" checked>
        </div>
    </div>
    <div class="layui-form-item">
        <input type="hidden" value="" class="fenlei_value">
        <label class="layui-form-label">分类</label>
        <div class="layui-input-inline fenlei_select" style="width:350px;">
            <select name="city" class="fenlei" lay-filter="fenlei">
                <?php if(!empty($fenlei)){
                    foreach($fenlei as $k=>$v){
                ?>
                        <option value="<?=$v['id']?>"><?=$v['name']?></option>
                    <?php }} ?>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">话题</label>
        <div class="layui-input-inline huati_div" style="width:350px;">
            <select name="city" class="huati">

            </select>

        </div>
        <div class="layui-form-mid layui-word-aux">请先选择分类</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">活动封面</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn activity_img" id="activity_img"><i class="layui-icon">&#xe67c;</i>添加活动封面</button>
            <input type="text" name="" class="wenzi1" style="width:300px;height:35px;margin-left:20px;display:none;">
            <span class="up1" style="width:300px;height:35px;margin-left:20px;display:none;color:red;"></span>
            <input type="hidden" name="activity_img_url" class="activity_img_url">
            <br><br>
            <div style="width:100px;height:100px;border:1px solid lightgreen;float:left;">
                <img src="" class="activity_img_http" style="width:100px;height:100px;">
            </div>
            <div class="layui-form-mid layui-word-aux" style="margin-left:10px;">必填</div>

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
           <button type="button" class="layui-btn save">保存</button>
           <button type="button" class="layui-btn back">返回</button>
        </div>
    </div>
</form>

<script>
    //保存
    $('.save').click(function () {
       var activity_big_small=$("input[name='activity_big_small']:checked").val()
       var fenlei=$(".fenlei").val()
       var huati=$(".huati").val()
       var activity_pic=$(".activity_img_url").val()
//        var a=[activity_big_small,fenlei,huati,activity_pic]
       c
    })
    $(function(){
        //上传
        layui.use('upload', function(){
            var upload = layui.upload;
            //上传横屏封面
            upload.render({
                elem: '#activity_img' //绑定元素
                , url: "<?=base_url("common/upload/normal_upload")?>"
                , data: {type: "image"}
                ,acceptMime: 'image/*'
                ,before:function(){
                    $(".up1").text("上传中。。。请等待");
                    $(".up1").show()
                }
                ,done: function(res){
                    //上传完毕回调
                    if(res.code==0){
                        layer.msg(res.msg,{time:1000},function(){
                            $(".up1").text("上传成功");
                            $('.activity_img_http').attr("src",res.data.file_url)
                            $('.activity_img_url').val(res.data.file_url)
                        })
                    }else{
                        layer.msg(res.msg,{time:2000})
                    }
                }
            });

        });

        //监听下拉框
        layui.use('form', function(){
            var form = layui.form;
            //监听下拉框选择
            form.on('select(fenlei)', function(data){
                //获得监听的值
                var type_id=data.value;
                //给下拉框赋值
                $('.fenlei_value').val(type_id);
                //获得下拉框的值
                var type_ids=$('.fenlei_value').val();
                //有参数传递，则是POST方式,这是下拉框局部刷新
                $(".huati").load("<?=base_url("activity/activity/get_huati")?>",{huati_id:type_ids},function(res){
                    //把数据json转化下
                    var arr = JSON.parse(res);
                    if(arr.code==0){
                        var arrs = arr.data;
                        $.each(arrs, function (i, n) {
                            $('.huati').append("<option value='" + n.id + "'>" + n.sub_title + "</option>");
                        });
                        layui.form.render('select');
                    }else{
                        layer.msg(arr.msg, {time: 2000},function(){
                            $('.huati').append("<option value=''></option>");
                        });
                        layui.form.render('select');
                    }
                });
            })
        })

        //没有先选择分类加个提示框
        $(".layui-input-inline.huati_div").click(function(){
            var fenlei_value=$(".fenlei_value").val();
            if(fenlei_value.length==0){
                layer.msg("请先选择分类",{time:2000})
            }
        })
        //返回
        $(".back").click(function(){
            window.history.back(-1);
        })
    })

</script>